package com.web.base.user.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;
import com.web.base.user.message.OfficeRequest;
import com.web.base.user.message.OfficeResponse;
import com.web.base.user.model.Office;

/**
 * 部门转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月16日
 */
public class OfficeConvertor
{
	private OfficeConvertor()
	{
	}
	
	public static Office toOffice(OfficeRequest request)
	{
		if (request == null)
			return null;
		
		Office office = new Office();
		office.setId(request.getId());
		office.setParentId(request.getParentId());
		office.setCode(request.getCode());
		office.setName(request.getName());
		office.setPic(request.getPic());
		office.setDescp(request.getDescp());
		office.setType(request.getType());
		office.setAddress(request.getAddress());
		office.setLongitude(request.getLongitude());
		office.setLatitude(request.getLatitude());
		office.setState(request.getState());
		office.setSort(request.getSort());
		office.setCreateDate(request.getCreateDate());
		office.setEndDate(request.getEndDate());
		return office;
	}
	
	public static OfficeResponse toResponse(Office office)
	{
		if (office == null)
			return null;
		
		OfficeResponse response = new OfficeResponse();
		response.setId(office.getId());
		response.setParentId(office.getParentId());
		response.setCode(office.getCode());
		response.setName(office.getName());
		response.setPic(office.getPic());
		response.setDescp(office.getDescp());
		response.setType(office.getType());
		response.setAddress(office.getAddress());
		response.setLongitude(office.getLongitude());
		response.setLatitude(office.getLatitude());
		response.setState(office.getState());
		response.setSort(office.getSort());
		response.setCreateDate(office.getCreateDate());
		response.setEndDate(office.getEndDate());
		return response;
	}
	
	public static List<OfficeResponse> toResponse(List<Office> list)
	{
		List<OfficeResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (Office office : list)
		{
			responseList.add(toResponse(office));
		}
		return responseList;
	}
	
	public static Map<Integer, OfficeResponse> toResponse(Map<Integer, Office> map)
	{
		Map<Integer, OfficeResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, Office> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<OfficeResponse> toResponse(Page<Office> page)
	{
		if (page == null)
			return null;
		
		Page<OfficeResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
